
from flask import Flask
from user.views import user_bp
from flask_cors import CORS

from db import db

app = Flask(__name__)
CORS(app,supports_credentials=True)
app.config.from_object('config')
app.register_blueprint(user_bp)
db.init_app(app)


if __name__ == '__main__':
    app.run(debug=True);



# from flask import Flask, make_response
# from flask_cors import CORS
# from flask_restful import fields,marshal
# from flask_sqlalchemy import SQLAlchemy
# from user import user_bp
# from database.table import Emp,Dept
#
# app = Flask(__name__)
# CORS(app,supports_credentials=True)
# app.register_blueprint(user_bp,url_prefix='/user')
# app.config.from_pyfile("config.py")#加载信息
#
# #创建sqlalchemy对象用于操作数据库
# db = SQLAlchemy(app)
#
# @app.route("/")
# def add():
#     # 创建Emp对象，因为emp表主键设置了自增，因此创建的对象不需要指定主键
#     emp = Emp(ename='张三', job='设计师', mgr=7369, hiredate='1999-02-22', sal=1000, deptno=1)
#     db.session.add(emp)
#     db.session.commit()
#     # 对象被插入数据库后，主键会被自动设置回对象
#     print(emp.empno)
#     return "添加成功"
#
#
# @app.route("/")
# def index():
#     return "欢迎访问";
#
#
# resoure_fields = {
#         'empno': fields.Integer,
#         'ename': fields.String,
#         'job': fields.String
#     }
#
#
# @app.route("/query")
# def query():
#     # emps = Emp.query.all()
#     # print(emps)
#     # emp = Emp.query.get(7369) 单条记录
#     emps = Emp.query.all()
#     res = {"code":20000,"emps":marshal(emps,resoure_fields)}
#     # return marshal(emp,resoure_fields) 两种方法都可以
#     # jsonify(marshal(emp,resoure_fields))
#     return res
#
#
# if __name__ == '__main__':
#     app.run(debug=True);
#
